// packageK/eGou/replenishList/replenishList.js
var o = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoding: false,
    result: [],
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getreplenishList()
  },
  getreplenishList() {
    var e = this,
      t = o.getNetAddresss("HuaYing.serviceStock");
    o._postNetWork({
      url: t,
      data: {
        uid: wx.getStorageSync('uid')
        // uid: 112095
      },
      success(l) {
        if (l.data.result == 1) {
          e.setData({
            list:l.data.data
          })
        } else {
          wx.showToast({
            title: l.data.msg,
            icon: "none"
          })
        }
      }
    })
  },
  onChange(e){
    this.setData({
      result: e.detail,
    });

  },
  getAll(){
    let arr = []
    if(this.data.result.length != this.data.list.length){
      this.data.list.forEach((item,index)=>{
        arr.push(String(index))
      })
    }
    this.setData({result:arr})
  },
  contrim(){
    let data = this.data.list
    let resu = this.data.result
    let goods_list = []
    let order_ids = ""
    if(resu.length == 0){
      wx.showToast({
        title: '请先选择商品',
        icon:"none"
      })
      return
    }

    for(let i=0;i<this.data.result.length;i++){
        goods_list.push({
          goods_id:data[resu[i]].goods_id,
          total:data[resu[i]].total,
        })
        order_ids += data[resu[i]].order_id + ","
    }

    var e = this,
      t = o.getNetAddresss("HuaYing.serviceStockApply");
    o._postNetWork({
      url: t,
      data: {
        uid: wx.getStorageSync('uid'),
        goods_list,
        order_ids
      },
      success(l) {
        if (l.data.result == 1) {
          e.setData({
            result:[],
          })
          e.getreplenishList()
          wx.showToast({
            title: "申请成功",
            icon: "none"
          })
        } else {
          wx.showToast({
            title: l.data.msg,
            icon: "none"
          })
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})